/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.activity.intent;

import java.util.Arrays;
import java.util.List;

import lt.marsrutai.mobile.android.activity.FastestRoutesResultActivity;
import lt.marsrutai.mobile.android.fragment.RoutesFragment.ClarificationStatus;
import lt.marsrutai.mobile.android.model.FastestRouteSearchBookmark;
import lt.marsrutai.mobile.android.model.RouteSearchResult;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class FastestRoutesResultIntentHolder extends IntentHolder {
    
    private static final String BOOKMARK = "bookmark";
    
    private static final String TRANSPORTS = "transports";
    private static final String SCOPE_FOLDER = "scopeFolder";

    private static final String STOP_FROM = "stopFrom";
    private static final String STOP_FROM_CLARIFY_STATUS = "stopFromClarifyStatus";
    private static final String STOP_TO = "stopTo";
    private static final String STOP_TO_CLARIFY_STATUS = "stopToClarifyStatus";
    private static final String DATE_TIME = "dateTime";
    private static final String IS_ARRIVAL = "isArrival";
    private static final String SEARCH_RESULT = "searchResult";

    private static final String WALK_SPEED = "walkSpeed";
    private static final String MAX_WALK_DISTANCE = "maxWalkDistance";
    private static final String CHANGE_DURATION = "changeDuration";
    private static final String MAX_RIDES = "maxRides";

    private static final String DIALOG_TITLE = "dialogTitle";
    private static final String DIALOG_CHOICES = "dialogChoices";
    private static final String DIALOG_ID = "dialogId";

    public FastestRoutesResultIntentHolder(Activity sourceActivity) {
        super(sourceActivity, FastestRoutesResultActivity.class);
    }

    public FastestRoutesResultIntentHolder(Intent intent) {
        super(intent);
    }

    public FastestRoutesResultIntentHolder(Bundle bundle) {
        super(bundle);
    }

    public void setScopeFolder(String scopeFolder) {
        intent.putExtra(SCOPE_FOLDER, scopeFolder);
    }

    public String getScopeFolder() {
        return intent.getStringExtra(SCOPE_FOLDER);
    }

    public void setStopFrom(String stopFrom) {
        intent.putExtra(STOP_FROM, stopFrom);
    }

    public String getStopFrom() {
        return intent.getStringExtra(STOP_FROM);
    }

    public void setStopTo(String stopTo) {
        intent.putExtra(STOP_TO, stopTo);
    }

    public String getStopTo() {
        return intent.getStringExtra(STOP_TO);
    }

    public void setDateTime(String dateTime) {
        intent.putExtra(DATE_TIME, dateTime);
    }

    public String getDateTime() {
        return intent.getStringExtra(DATE_TIME);
    }

    public void setIsArrivalInd(boolean value) {
        intent.putExtra(IS_ARRIVAL, value);
    }

    public boolean getIsArrivalInd() {
        return intent.getBooleanExtra(IS_ARRIVAL, false);
    }
    
    public int getDialogTitle() {
        return intent.getIntExtra(DIALOG_TITLE, 0);
    }
    
    public void setDialogTitle(int dialogTitle) {
        intent.putExtra(DIALOG_TITLE, dialogTitle);
    }

    public List<String> getDialogChoices() {
        return Arrays.asList(intent.getStringArrayExtra(DIALOG_CHOICES));
    }

    public void setDialogChoices(List<String> choices) {
        intent.putExtra(DIALOG_CHOICES, choices.toArray(new String[choices.size()]));
    }

    public int getDialogId() {
        return intent.getIntExtra(DIALOG_ID, 0);
    }

    public void setDialogId(int id) {
        intent.putExtra(DIALOG_ID, id);
    }
    
    public RouteSearchResult getSearchResult() {
        return intent.getParcelableExtra(SEARCH_RESULT);
    }
    
    public void setSearchResult(RouteSearchResult result) {
        intent.putExtra(SEARCH_RESULT, result);
    }

    public void setStopFromClarifyStatus(ClarificationStatus stopFromClarifyStatus) {
        if (stopFromClarifyStatus != null) {
            intent.putExtra(STOP_FROM_CLARIFY_STATUS, stopFromClarifyStatus.name());
        }
    }

    public ClarificationStatus getStopFromClarifyStatus() {
        String result = intent.getStringExtra(STOP_FROM_CLARIFY_STATUS);
        return result != null ? ClarificationStatus.valueOf(result) : null;
    }

    public void setStopToClarifyStatus(ClarificationStatus stopToClarifyStatus) {
        if (stopToClarifyStatus != null) {
            intent.putExtra(STOP_TO_CLARIFY_STATUS, stopToClarifyStatus.name());
        }
    }

    public ClarificationStatus getStopToClarifyStatus() {
        String result = intent.getStringExtra(STOP_TO_CLARIFY_STATUS);
        return result != null ? ClarificationStatus.valueOf(result) : null;
    }

    public void setMaxRides(int maxRides) {
        intent.putExtra(MAX_RIDES, maxRides);
    }
    
    public int getMaxRides() {
        return intent.getIntExtra(MAX_RIDES, 0);
    }

    public void setChangeDuration(int changeDuration) {
        intent.putExtra(CHANGE_DURATION, changeDuration);
    }
    
    public int getChangeDuration() {
        return intent.getIntExtra(CHANGE_DURATION, 0);
    }

    public void setMaxWalkDistance(int maxWalkDistance) {
        intent.putExtra(MAX_WALK_DISTANCE, maxWalkDistance);
    }
    
    public int getMaxWalkDistance() {
        return intent.getIntExtra(MAX_WALK_DISTANCE, 0);
    }

    public void setWalkSpeed(int walkSpeed) {
        intent.putExtra(WALK_SPEED, walkSpeed);
    }
    
    public int getWalkSpeed() {
        return intent.getIntExtra(WALK_SPEED, 0);
    }

    public void setTransports(String transports) {
        intent.putExtra(TRANSPORTS, transports);
    }

    public String getTransports() {
        return intent.getStringExtra(TRANSPORTS);
    }

    public void setBookmarkRepresentation(FastestRouteSearchBookmark bookmarkRepresentation) {
        intent.putExtra(BOOKMARK, bookmarkRepresentation);
    }

    public FastestRouteSearchBookmark getBookmarkRepresentation() {
        return intent.getParcelableExtra(BOOKMARK);
    }
}
